HOMEWORK 1,
Due Tuesday, Jan 16th, before class
getchar(GRADE) ;
if (GRADE = 'A')
printf("A
Grade") ;
else if (GRADE = 'B')
printf("B
Grade");
else if (GRADE = 'C')
printf("C Grade");
A)
main(){
int i, sum;
i = 0;
sum = i;
printf("%d ", sum) ;
while (i < 15) {
i += 5;
sum += i ;
printf("%d ",sum) ;
}
printf("\n %d",sum) ;
}
B)
main() {
int i, x = 0;
for (i=1; i <= 10; i++)
if (floor(log2(i)) == log2(i))
x++;
printf("
%d ",x) ;
}
C)
main(){
int
i, x = 0;
for (i=0; i<5; i++){
switch(i){
case 0: {x++; break ;}
case 1: {x++; break ;}
case 2: {x++; break ;}
case 3: {x += 2; }
case 4: {x += 3; }
}
printf("x = %d", x) ;
x = 0 ;
}
}
D)
main(){
int
i = 0;
printf("%d
", i++) ;
printf("%d",
--i) ;
}
a.
char **a ;
b.
char (*a)[] ;
c.
int *f() ;
d.
int *(*f)() ;
e.
int (*f())[] ;
7. What will be the output of the
following program?
main(int
argc, char * argv[]){
int i ;
for (i = 0; i< argc; i++){
printf("%c
",argv[i][i]) ;
}
}
8. In the following program, which of the following expressions evaluate to the contents of p[1]?
main(){
char p[] = {'a', 'b', 'c'};
char *q;
q
= p ;
}
a)
*++q
b)
*(++q)
c)
*(q+1)
d)
*(p+1)
e)
1+p